package com.application.fabric.users.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeoutException;

@Slf4j
/*全局异常处理*/
@RestControllerAdvice
public class GlobalExceptionHandling {
    @Autowired
    private Dealmsg dealmsg;
//    @ExceptionHandler(value = RuntimeException.class)
//    public Map<String,Object> handler(RuntimeException e){
//        log.error("运行异常:-----------",e.getMessage());
//        return dealmsg.failmsg();
//    }

    @ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
    @ExceptionHandler(value = TimeoutException.class)
    public Map<String,Object> timeout(TimeoutException e){
        log.error("连接超时:-----------",e.getMessage());
        return dealmsg.timeoutmsg();
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(value = IOException.class)
    public Map<String,Object> ioe(TimeoutException e){
        log.error("文件传输异常:-----------",e.getMessage());
        return dealmsg.ioemsg();
    }
}
